//
//  receiveLoginByPP.m
//  tcpoctest
//
//  Created by gump on 5/16/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveLoginByPP.h"

#import "userdb.h"
#import "PromptLoginDataSource.h"
#import "FirendCircleDataSource.h"
#import "sendFirCirBgImage.h"
#import "sendPotocol.h"

#import "sendTaskQuery.h"
#import "sendPersonToken.h"

@implementation receiveLoginByPP

-(void)processreceive
{
    [logicsb ReadChar];
    
    int iindex = [logicsb ReadChar];
    
    [MobClick event:T_UMENG_LOGINMAIL];
    
    switch (iindex)
    {
        case LFM_SUCESS:
        case LFM_DIVCECHANGE:
        {
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
            
            [DataControl shareControl].blogin = true;
            
            [[DataBaseCtrol shareControl].userdatabase insertUserByPP:
             [DataControl shareControl].personDS.uinfo.ppNumber
                                                               withPS:[DataControl shareControl].personDS.uinfo.ps];
            [DataControl shareControl].personDS.uinfo.mail = [logicsb ReadUnencodeString];
            
            [[DataBaseCtrol shareControl].userdatabase insertUser:[DataControl shareControl].personDS.uinfo.mail
                                                           withPS:[DataControl shareControl].personDS.uinfo.ps];
            
            setLocalMail([DataControl shareControl].personDS.uinfo.mail);
            setLocalPP([DataControl shareControl].personDS.uinfo.ppNumber);
            
            if ([[DataControl shareControl].promptloginDS IsInitData]) {
                [[DataBaseCtrol shareControl] initData];
            }
            
            [[netManager sharedNetManager].sendp SendMainIndex:ID_MI_ADDFIREND
                                               WithSecondIndex:AFI_READCARELENGTH];
            [[netManager sharedNetManager].sendp SendMainIndex:ID_MI_ADDFIREND
                                               WithSecondIndex:AFI_BECARELENGTH];
            [[netManager sharedNetManager].sendp SendMainIndex:ID_MI_OFFLINEMSG
                                               WithSecondIndex:ID_MI_OFFLINEMSG];
            
            [[netManager sharedNetManager].sendTaskQ SendTaskTheQuery];
            
            [[DataControl shareControl].UICommendDS addUICommand:UI_UPDATEFIRENDV];
            
            [[DataControl shareControl].LCDS addLogicCommand:LC_SENDPERSONINFO];
            [[DataControl shareControl] SearchInfo:
             [DataControl shareControl].personDS.uinfo.mail];
            
            if (IsFirstLogin() &&
                iindex != LFM_DIVCECHANGE) {
                if (![[DataControl shareControl].personDS.strToken isEqualToString:@""]) {
                    [[netManager sharedNetManager].sendPersonT
                     sendToken:[DataControl shareControl].personDS.strToken];
                }
            }
            
            else if ([DataControl shareControl].iGameState == GMS_CONFIG &&
                iindex != LFM_DIVCECHANGE) {
                if (![[DataControl shareControl].personDS.strToken isEqualToString:@""]) {
                    [[netManager sharedNetManager].sendPersonT
                     sendToken:[DataControl shareControl].personDS.strToken];
                }
            }
            
            if ([[DataControl shareControl].promptloginDS IsShowMain]) {
                [[DataControl shareControl].UICommendDS addUICommand:UC_SHOWMAIN];
            }
            else
            {
                [[DataControl shareControl] SetGameState:[DataControl shareControl].miOldGameState];
            }
            
            if ([[DataControl shareControl].promptloginDS ISPromptLogin]) {
                [[DataControl shareControl].UICommendDS addUICommand:UC_PROMPT_LOGIN];
            }
            
            if (iindex == LFM_DIVCECHANGE)
            {
                [[LogicControl sharedLogicControl] ChangeDevice];
            }
            
            
        }
            break;
        case LFM_MAIL:
        case LFM_PS:
        case LFM_MAILLOCK:
        case LFM_DIVCELOCK:
        {
            [[DataControl shareControl] SetLoginFailID:iindex];
            [[DataControl shareControl].UICommendDS addUICommand:UI_LOGINFAIL];
        }
            break;
        default:
            break;
    }
    
    [self ShowLog];
}

@end
